<?php

require_once("view/utils/functions.php");
require_once("model/userFacade.php");
require_once("model/adminFacade.php");


$page = "";
if (checkParam("page"))
	$page = getParam("page");
	
	
session_start();
	
switch($page){

	case "rss":
		$GLOBALS["recipesMini"] = obtainLastRecipes(5);
		require_once("view/pages/rss.php");
		break;
	
	case "error":
		$GLOBALS["message"] = $_SESSION["errorMessage"];
		require_once("view/pages/error.php");
		break;	
	
	case "logout":
		require_once("view/pages/logout.php");
		break;
	
	case "successful":
		require_once("view/pages/successful.php");
		break;
	
	case "checkrecipe":
		require_once("view/pages/checkRecipe.php");
		break;
	
	case "admin":
		if (checkParam("state")){
			$GLOBALS["state"] = getParam("state");
		}
		require_once("view/pages/admin.php");
		break;
	
	case "checklogin":
		require_once("view/pages/checkLogin.php");
		break;
	
	case "login":
		if (checkParam("state")){
			$GLOBALS["state"] = getParam("state");
		}
		require_once("view/pages/login.php");
		break;
		
		
	case "viewrecipe":
		if (checkParam("recipeid")) {
			$recipeId = getParam("recipeid");
			$GLOBALS["result"] = obtainRecipeById($recipeId);
			$GLOBALS["categories"] = obtainCategories();
			require_once("view/pages/viewRecipe.php");			
		}
		else { 
			redirectError("page not found");
		}
		break;
	
	case "recipesbycategory":
		if (checkParam("labelid")) {
					
			$labelId = getParam("labelid");
			$GLOBALS["recipesMini"] = obtainRecipesByLabel($labelId);
			$GLOBALS["categories"] = obtainCategories();
			$GLOBALS["category"] = obtainLabelById($labelId);
			require_once("view/pages/recipesByCategory.php");		
		}
		else { //TODO
			redirectError("page not found");
		}
		break;
		
	
	case "allrecipes":
										
			$GLOBALS["recipesMini"] = obtainRecipes();
			$GLOBALS["categories"] = obtainCategories();
			require_once("view/pages/allrecipes.php");		
		
		break;
	
	default:
		$GLOBALS["categories"] = obtainCategories();
		require_once("view/pages/home.php");
	    break;
}

?>


